<template>
  <section class="link-box">
    <div class="link-class">
      <a href="javascript:void(0)"
         :title="row.contractNo"
         @click="handleClick">{{ row.contractNo }}
      </a>
    </div>
    <span>
      <i class="el-icon-copy-document icon"
         @click="handleCopy" />
    </span>
    <span v-if="row.signMode === 2 && row.contractStatus != 1"
          class="ml5">
      <icon-svg icon-name="dianziyinzhang"
                class-name="iconClass" />
    </span>
  </section>
</template>

<script>
export default {
  name: "ContractNoLink",
  props: {
    row: {
      type: Object,
      default: () => { }
    },
    url: String
  },
  data () {
    return {
      userInfo: sessionStorage.getItem('userInfo')
    }
  },
  computed: {
    path () {
      return this.url
      // return [1, 3].includes(this.row.contractStatus) ? "createContract" : "contractPreview"
    },
    user () {
      return JSON.parse(this.userInfo)
    }
  },
  methods: {
    handleClick () {
      if ([4, 5].includes(this.row.contractStatus)) {
        if (this.row.signMode === 2 && !this.row?.fileStats) {
          return this.$message({ type: "warning", message: "文件不存在" });
        }
        const { href } = this.$router.resolve({
          name: "contractPreviewWindow",
          query: {
            contractId: this.row.contractId,
            // contractType: this.user.tenantId === this.row.tenantIdOne ? 2 : 1
          }
        });
        window.open(href, "_blank");
      } else {
        this.$router.push({
          name: this.path,
          query: {
            contractId: this.row.contractId,
            // contractType: this.user.tenantId === this.row.tenantIdOne ? 2 : 1
          }
        });
      }
    },
    // 复制
    handleCopy () {
      var copyValueInput = document.createElement("input");
      copyValueInput.value = this.row.contractNo;
      document.body.appendChild(copyValueInput);
      copyValueInput.select();
      document.execCommand("copy");
      this.$message({ type: "success", message: "复制成功" });
      document.body.removeChild(copyValueInput);
    }
  }
};
</script>
<style scoped>
.link-box {
  display: flex;
  align-items: center;
}
.link-class {
  max-width: 200px !important;
  color: var(--prev-color-primary) !important;
  display: block;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  text-align: center;
}
.iconClass {
  margin-left: 2px;
  width: 16px !important;
  height: 16px !important;
  cursor: pointer;
}
.ml5 {
  margin-left: 5px;
}
.icon {
  margin-left: 2px;
  margin-top: 3px;
  width: 16px;
  height: 16px;
  cursor: pointer;
  color: chocolate;
}
</style>